using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Security;
namespace Net35.Xrm.Sdk
{
	[Serializable]
	public sealed class SaveChangesException : Exception
	{
		private const string _message = "An error occured while processing this request.";
		public SaveChangesResultCollection Results
		{
			get;
			private set;
		}
		public SaveChangesException()
		{
		}
		public SaveChangesException(string message) : base(message)
		{
		}
		public SaveChangesException(string message, Exception exception) : base(message, exception)
		{
		}
		public SaveChangesException(SaveChangesResultCollection results) : this("An error occured while processing this request.", results)
		{
		}
		public SaveChangesException(string message, SaveChangesResultCollection results) : this(message, SaveChangesException.GetException(results), results)
		{
		}
		public SaveChangesException(Exception innerException, SaveChangesResultCollection results) : this("An error occured while processing this request.", innerException, results)
		{
		}
		public SaveChangesException(string message, Exception innerException, SaveChangesResultCollection results) : base(message, innerException)
		{
			this.Results = results;
		}
		private SaveChangesException(SerializationInfo info, StreamingContext context) : base(info, context)
		{
		}
		[SecurityCritical]
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
		}
		private static Exception GetException(IEnumerable<SaveChangesResult> results)
		{
			return (
				from r in results
				where r.Error != null
				select r.Error).FirstOrDefault<Exception>();
		}
	}
}
